/**
 * 流水线和任务相关类型定义
 */

import { TaskStatus, TriggerType } from './enums'
import type { WorkflowDefinition } from './workflow'

/**
 * 流水线
 */
export interface Pipeline {
  id: number
  name: string
  description?: string
  workflowDefinitionId: number
  repositoryUrl: string
  branch: string
  isEnabled: boolean
  createdAt: string
  updatedAt?: string
  workflowDefinition?: WorkflowDefinition
  triggers?: PipelineTrigger[]
}

/**
 * 流水线触发器
 */
export interface PipelineTrigger {
  id: number
  pipelineId: number
  triggerType: TriggerType
  isEnabled: boolean
  configuration?: string
}

/**
 * 流水线实例
 */
export interface PipelineInstance {
  id: number
  pipelineId: number
  commitHash: string
  commitMessage: string
  commitAuthor?: string
  status: TaskStatus
  startTime: string
  endTime?: string
  triggeredBy: string
  triggerType?: TriggerType
  pipeline?: Pipeline
}

/**
 * 任务实体
 */
export interface TaskEntity {
  taskId: number
  instanceId: number
  stepName: string
  stepType: number
  stepConfig?: string
  status: TaskStatus
  nodeId: string
  nodeName?: string
  startTime: string
  endTime?: string
  errorMessage?: string
  retryCount?: number
}

/**
 * 任务实例统计
 */
export interface InstanceStatistics {
  instanceId: number
  totalTasks: number
  pendingTasks: number
  runningTasks: number
  successTasks: number
  failedTasks: number
  cancelledTasks: number
  progress: number
  estimatedEndTime?: string
}

/**
 * 创建流水线请求
 */
export interface CreatePipelineRequest {
  name: string
  description?: string
  workflowDefinitionId: number
  repositoryUrl: string
  branch: string
  triggers?: Omit<PipelineTrigger, 'id' | 'pipelineId'>[]
}

/**
 * 执行流水线请求
 */
export interface ExecutePipelineRequest {
  commitHash?: string
  branch?: string
  parameters?: Record<string, any>
}

/**
 * 任务日志
 */
export interface TaskLog {
  taskId: number
  timestamp: string
  level: 'info' | 'warning' | 'error' | 'debug'
  message: string
}
